/*
Problem Description
Given a sequence 1,2,3,......N, your job is to calculate all the possible sub-sequences that the sum of the sub-sequence is M.
 

Input
Input contains multiple test cases. each case contains two integers N, M( 1 <= N, M <= 1000000000).input ends with N = M = 0.
 

Output
For each test case, print all the possible sub-sequence that its sum is M.The format is show in the sample below.print a blank line after each test case.
 

Sample Input
20 10
50 30
0 0
 

Sample Output
[1,4]
[10,10]

[4,8]
[6,9]
[9,11]
[30,30]
 */
package com.yuan.algorithms.training20150807;

import java.util.Scanner;

/**
 * @author YouYuan
 * @eMail E-mail:1265161633@qq.com
 * @Time 创建时间：2015年8月9日 下午3:58:23
 * @Explain 说明:子列的起点和子列元素的个数，分别记为i，j。由等差数列求和公式，得(i+(i+j-1))*j/2 = m [1式] 
 * (2*i + j - 1) * j / 2 = m [2式] 
 * (2ij + j^2 - j) / 2 = m 
 * 2ij + j^2 - j = 2m
 * 2ij = 2m - j^2 + j 
 * i = (2m - j^2 + j) / 2j
 * i = (2m/j - j + 1) / 2 [3式]
 * 将i，j代回2式，成立则[i,i+j-1]满足条件。
 * 注意j最小为1，而由2式，得（j+2*i）*j=2*M，而i>=1，故j<=(int)sqrt(2*M).
 */
public class 子序列求和匹配 {

	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		while (in.hasNext()) {
			int n = in.nextInt();
			int m = in.nextInt();
			if (n == 0 && m == 0) {
				break;
			}
			for (int j = (int) Math.sqrt(2*m); j > 0; j--) {
				int i = (2*m/j - j + 1) / 2;
				if ((2*i + j - 1) * j / 2 == m) {
					System.out.printf("[%d,%d]", i, i + j - 1);
					System.out.println();
				}
			}
			System.out.println();
		}
	}

}
